<blockquote>
    <p>Jar 模式启动 [推荐]</p>
    <footer>通过可执行jar文件运行web项目, 也就是所谓的微服务模式， 启动命令<code>java -jar 项目.jar</code>
    </footer>
</blockquote>
<h5>示例 Tomcat 启动 (默认内置tomcat8)</h5>
<blockquote>
    <footer>有人可能会问为何不能设置webapp目录, 微服务本来就是只是负责动态Api口, 静态资源靠Nginx处理, 达到动静态分离的效果, 至于会出现跨域后面会讲解</footer>
</blockquote>
<pre class="code brush:java">
    import cn.jants.common.annotation.service.Application;
    import cn.jants.core.startup.JTomcat;

    /**
     * Tomcat 方式启动
     *
     * @author MrShun
     * @version 1.0
     * @Date 2017/12/20
     */
    @Application
    public class DemosApplication {

        /**
         * 可以将args 作为jar运行的传入参数
         */
        public static void main(String[] args)  {
            //只是作为Api微服务启动, 没有webapp
            //JTomcat.run(DemosApplication.class, 80);

            /**
             * 参数一：指定启动类
             * 参数三：指定端口号
             * 参数四：指定contextPath
             */
            JTomcat.run(DemosApplication.class, 80, "/demo");

        }
    }

</pre>
<h5>示例 Jetty 启动, 需要引入jetty依赖包</h5>
<pre class="code brush:xml">
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>8.1.7.v20120910</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-webapp</artifactId>
            <version>8.1.7.v20120910</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-jsp</artifactId>
            <version>8.1.7.v20120910</version>
        </dependency>

</pre>
Jetty 启动
<pre class="code brush:java">
import cn.jants.common.annotation.service.Application;
import cn.jants.core.startup.Jetty;

/**
 * Jetty 方式启动
 *
 * @author MrShun
 * @version 1.0
 * @Date 2017/12/20
 */
@Application
public class DemosApplication {

    /**
     * 可以将args 作为jar运行的传入参数
     */
    public static void main(String[] args) {
        //只是作为Api微服务启动, 没有webapp
        //Jetty.run(DemosApplication.class, 80);

        /**
         * 参数一：指定启动类
         * 参数三：指定端口号
         * 参数四：指定contextPath
         */
        Jetty.run(DemosApplication.class, 80, "/demo");

    }
}


</pre>
<p>Maven build 打包配置，需要指定启动类, 已经依赖lib位置</p>
<pre class="code brush:xml">
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8&lt;/source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>cn.jants.demos.DemosApplication</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <includeScope>runtime</includeScope>
                </configuration>
            </plugin>
        </plugins>

        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
            </resource>
        </resources>
    </build>
</pre>
<h5>maven package 编译文件</h5>
<img src="debug/jar-bulid.jpg" style="max-width: 1000px;"/>
<h5>cmd 命令执行</h5>
<img src="debug/jar-cmd.jpg" style="max-width: 1000px;"/>
<script type="text/javascript">
    $(function () {
        SyntaxHighlighter.highlight();
        $(".toolbar").remove();
    });
</script>